package com.anche.cywebnew.Utils.query;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;


public class SendSms
{
	private static String URL = "http://56.32.4.182:8021/sms-boot/sms/send/sendSms";

	public static void main(String[] args)
	{
		String userName = "用户名";
		String password = "密码";
		String phone = "手机号码";
		String msg = "短信内容";
		String longid = "分配特服号码（原来有的不变）";
		
		sendSms(userName, password, phone, msg, longid);
	}
	
	public static void sendSms(String userName, String passWord, String phone, String msg, String longid)
	{
		String token = MakeToken.getToken(userName, passWord);
		if (token.length() > 1)
		{
			JSONObject param = new JSONObject();
			param.put("msgContent", msg);
			param.put("phones", phone);
			param.put("longId", longid);
			
			String id = "0";
			String response = HttpUtil.post(URL, token, param.toString());
			JSONObject obj = JSONObject.parseObject(response);
			
			/*
			 * {"success":true,"message":"发送成功！","code":200,"result":{"sendIds":["1712669467308507137"]},"timestamp":1697167195482}
			 */
			if (200 == obj.getIntValue("code"))
			{
				JSONObject result = obj.getJSONObject("result");
				// {"sendIds":["1712669467308507137"]}
				JSONArray sendid = result.getJSONArray("sendIds");
				// ["1712669467308507137"]
				id = sendid.getString(0);
				
				System.out.println(id);
			}
		}
	}
}
